<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray;
use  App\Models\Order;

class CustomerExport implements FromArray
{

    public function array(): array
    {
        $data = [
            [
                '序号',
                '商品名称',
                '商品图片',
                '订单编号',
                '商品类型',
                '所属供应商',
                '所属医护工作室',
                '商品规格',
                '商品备注',
                '收货人姓名',
                '联系方式',
                '地址',
                '收货人姓名',
                '联系方式',
                '商品数量',
                '创建时间',
                '付款时间',
                '订单状态',
                '价格',
            ],
        ];
        /*
        "id" => "ID",
            "order_goods.goods_name" => "商品名称",
            "order_goods.goods_img" => "商品图片",
            "sn" => "订单编号",
            "order_source" => "商品类型",
            "distributor.name" => "所属供应商",
            "work.work_name" => "所属医护工作室",
            "order_goods.product_standard" => "商品规格",
            "order_goods.product_remark" => "商品备注",
            "orderaddress.name" => "收货人姓名",
            "orderaddress.phone" => "联系方式",
            ",

            "nums" => "商品数量",
            "created_at" => "创建时间",
            "pay_time" => "付款时间",
            "order_status" => "订单状态",
            "total_price" => "价格",
        */
        $userDatas = Order::where('order_type', 2)->get();

        $option = [
            0 => '未完成',
            1 => '已完成',
            2 => '申请售后',
            3 => '售后完成',
            4 => '取消订单',
        ];
        $Source = [
            1 => '工作室商品',
            2 => '供应商商品',
        ];
        foreach ($userDatas as $k => $v) {

            $data[] = [
                $v->id,                             //ID
                $v->order_goods->goods_name,        //商品名称
                $v->order_goods->goods_img,         //商品图片
                $v->sn,                             //订单编号
                $Source[$v->order_source] ?? '',  //商品类型
                $v->distributor->name,              //所属供应商
                $v->work->work_name,                //所属医护工作室
                $v->order_goods->product_standard,  //商品规格
                $v->order_goods->product_remark,    //商品备注
                $v->orderaddress->name,             //收货人姓名
                $v->orderaddress->phone,            //联系方式
                $v->orderaddress->detail,           //地址
                $v->orderaddress->name,             //收货人姓名
                $v->orderaddress->phone,            //联系方式
                $v->nums,                           //商品数量
                $v->created_at,                     //创建时间
                $v->pay_time,                       //付款时间
                $option[$v->order_status] ?? '',//订单状态
                $v->total_price,                    //价格
            ];
        }
        return $data;
    }

}